<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8"/>
    <title>Java-ES仿京东实战</title>
    <link rel="stylesheet" th:href="@{/css/style.css}"/>
</head>

<body class="pg">
<div class="page" id="app">
    <div id="mallPage" class=" mallist tmall- page-not-market ">

        <!-- 头部搜索 -->
        <div id="header" class=" header-list-app">
            <div class="headerLayout">
                <div class="headerCon ">
                    <!-- Logo-->
                    <h1 id="mallLogo">
                        <img th:src="@{/images/jdlogo.png}" alt="">
                    </h1>

                    <div class="header-extra">

                        <!--搜索-->
                        <div id="mallSearch" class="mall-search">
                            <form name="searchTop" class="mallSearch-form clearfix">
                                <fieldset>
                                    <legend>天猫搜索</legend>
                                    <div class="mallSearch-input clearfix">
                                        <div class="s-combobox" id="s-combobox-685">
                                            <div class="s-combobox-input-wrap">
                                                <input v-model="keyword" type="text" autocomplete="off" value="dd"
                                                       id="mq"
                                                       class="s-combobox-input" aria-haspopup="true">
                                            </div>
                                        </div>
                                        <button @click.prevent="searchPage" type="submit" id="searchbtn">搜索</button>
                                    </div>
                                </fieldset>
                            </form>
                            <ul class="relKeyTop">
                                <li><a>狂神说Java</a></li>
                                <li><a>狂神说前端</a></li>
                                <li><a>狂神说Linux</a></li>
                                <li><a>狂神说大数据</a></li>
                                <li><a>狂神聊理财</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- 商品详情页面 -->
        <div id="content">
            <div class="main">
                <!-- 品牌分类 -->
                <form class="navAttrsForm">
                    <div class="attrs j_NavAttrs" style="display:block">
                        <div class="brandAttr j_nav_brand">
                            <div class="j_Brand attr">
                                <div class="attrKey">
                                    品牌
                                </div>
                                <div class="attrValues">
                                    <ul class="av-collapse row-2">
                                        <li><a href="#"> 狂神说 </a></li>
                                        <li><a href="#"> Java </a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>

                <!-- 排序规则 -->
                <div class="filter clearfix">
                    <a class="fSort fSort-cur">综合<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">人气<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">新品<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">销量<i class="f-ico-arrow-d"></i></a>
                    <a class="fSort">价格<i class="f-ico-triangle-mt"></i><i class="f-ico-triangle-mb"></i></a>
                </div>

                <!-- 商品详情 -->
                <div class="view grid-nosku">

                    <div class="product" v-for="item in results">
                        <div class="product-iWrap"  >
                            <!--商品封面-->
                            <div class="productImg-wrap" @click="GoDetail(item.href)">
                                <a class="productImg">
                                    <img :src="item.img">
                                </a>
                            </div>
                            <!--价格-->
                            <p class="productPrice">
                                <em>{{item.price}}</em>
                            </p>
                            <!--标题-->
                            <p class="productTitle">
                                <a v-html="item.title" :href="item.href"></a>
                            </p>
                            <!-- 店铺名 -->
                            <div class="productShop">
                                <span>店铺： 狂神说Java </span>
                            </div>
                            <!-- 成交信息 -->
                            <p class="productStatus">
                                <span>月成交<em>999笔</em></span>
                                <span>评价 <a>3</a></span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div style="text-align:center;">
        <div style="display: inline-block;float: none;">
            <!--            <el-pagination-->
            <!--                    class="pagination"-->
            <!--                    @current-change="handleCurrentChange"-->
            <!--                    :current-page.sync="currentPage"-->
            <!--                    :page-size="pageLimit"-->
            <!--                    layout="prev, pager, next, jumper"-->
            <!--                    :total="dataTotalLength">-->
            <!--            </el-pagination>-->
            <el-pagination @size-change="changeSizeHandle" @current-change="currentChangeHandle"
                           :current-page="currentPage" layout="total, sizes, prev, pager, next, jumper"
                           :page-size="20"
                           :total="total" background>
            </el-pagination>

        </div>
    </div>

</div>
<script th:src="@{/js/vue.min.js}"></script>
<script th:src="@{/js/axios.min.js}"></script>
<!-- 引入样式 -->
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<!-- 引入组件库 -->
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {}
        },
        data: {
            keyword: '',  //搜索关键字
            results: [],  //搜索结果
            dataTotalLength: 5, //数据总量total
            pageLimit: 5, //每页的数据量


            roleList: [],          // 总数据
            total: 0,             // 总条数，根据接口获取数据长度(注意：这里不能为空)
            size: 20,             //默认每页数据量
            currentPage: 1        // 默认显示第一页

        },
        methods: {
            // 每页显示的条数改变
            changeSizeHandle(val) {
                this.size = val                   // 改变每页显示的条数
                this.currentPage = 1              // 注意：在改变每页显示的条数时，要将页码显示到第一页
                this.getInfo()                    // 点击每页显示的条数时，显示第一页
                console.log(`每页 ${val} 条`)
            },


            // current-change用于监听页数改变，而内容也发生改变
            currentChangeHandle(val) {
                this.currentPage = val                // 改变默认的页数
                this.getInfo()                        // 切换页码时，要获取每页显示的条数
                console.log(`当前页: ${val}`)
            },


            // 查询信息
            async getInfo() {
                let pageNo = (this.currentPage - 1) * this.size + 1;
                let pageSize =  this.size ;
                axios.get("/search/" + this.keyword + "/"+pageNo+"/"+pageSize)
                    .then(res => {
                        console.log(res.data)
                        this.results = res.data.data.resultList;
                        this.total = res.data.data.totalCount;
                    })
                    .catch(error => {
                        console.log(error)
                    })
            },

            GoDetail(url){
                window.open(url)
            },



            searchPage() {
                var keyword = this.keyword;
                console.log(keyword)
                axios.get("/search/" + keyword + "/1/20").then(res => {
                    console.log(res.data)
                    this.results = res.data.data.resultList;

                    this.total = res.data.data.totalCount;

                    //this.changeSizeHandle(20)

                })
            },

            handleCurrentChange(page) {
                this.currentPage = page //点击的时候把拿到的页码 赋值给组件
                this.searchPage(page)
            }
        }
    })
</script>

</body>
</html>